package com.usian.controller;

import com.usian.pojos.Student;
import com.usian.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping("/findStudent")
    public String findStudent(Model model){

        List<Student> list = studentService.list();

        model.addAttribute("student",list);

        return "student";
    }

    @PostMapping("/import")
    public String importFile(MultipartFile importFile){

        studentService.importFiel(importFile);

        return "redirect:/student/findStudent";
    }
}
